package com.example.sale.Service.imply;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.sale.Mapper.UserMapper;
import com.example.sale.Service.IUserService;
import com.example.sale.True.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService extends ServiceImpl<UserMapper, User> implements IUserService{
     @Autowired
     private UserMapper userMapper;

    @Override
    public boolean isUsernameExists(String username) {
        User existingUser = userMapper.findByUsername(username);
        return existingUser!=null;
    }
    public Integer isUserExists(String username,String password,String role) {
        User existUser = userMapper.findUser(username,password,role);
        if (existUser !=null){
            return existUser.getId();
        }
        else {
            return null;
        }
    }

    @Override
    public boolean removeBYTokenId(Integer userid) {
        Boolean rowsAffected =userMapper.removeBYTokenId(userid);
        return rowsAffected;
    }
    public void  deleteProductListDetailByUserId(Integer userid){
        userMapper.deleteProductListDetailByUserId(userid);
    }

    @Override
    public void deleteFeedBackByUserId(Integer userid) {
        userMapper.deleteFeedBackByUserId(userid);
    }

    @Override
    public String getPassword(Integer id) {
        String password = userMapper.FindPassword(id);
        return password;
    }

    @Override
    public boolean save(User entity) {
        return super.save(entity);
    }

}
